<template>
    <div class="stats-top">
      当前时间：{{timeStr}}<br />
      当前考试批次：{{batchInfo && batchInfo.batch}}&nbsp;
      当日进度：{{batchInfo && batchInfo.batch}}/14
      <img src="@/assets/img/stats/title.png" alt="title" class="title-img">
      <div class="user-info">
        欢迎您 ，{{userData.roleName}}
        <span @click="back">返回</span>
      </div>
    </div>
</template>

<script>
import {formatDate} from "@/common/util.js"
  
export default {
  props: ['batchInfo'],
  components: {},
  data () {
    return {
      timeStr: '',
      st: null,
      userData: []
    }
  },
  mounted ()  {
    this.getNowTime()
    if (sessionStorage.getItem('userData') === 'undefine') {
      this.$message.error('无法获取用户角色！')
    } else {
      let obj = JSON.parse(sessionStorage.getItem('userData'))
      if (obj) {
        this.userData = obj
      } else {
        this.$router.push({ name: 'login' })
      }
    }
  },
  destroyed() {
    clearTimeout(this.st)
  },
  methods: {
    back(){
      window.history.back()
    },
    getNowTime () {
      let date = new Date().getTime()
      this.timeStr = formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      this.st = setTimeout(this.getNowTime, 500)
    }
  },
  computed: {}
}
</script>

<style>
</style>
